import json
import os
basic_path = str(os.path.dirname(__file__)) + "\\"
major_path = basic_path + "..\\..\\major_map\\bom_major_map.json"

# 打开 JSON 文件
with open(major_path, 'r', encoding='utf-8') as f:
    data = json.load(f)

json_update = {}

for key, value in data.items():
    print(key)
    if value['name'] == '本科（普通教育）':
        json_update['本科'] = {}
        for key1, value1 in value.items():
            if key1 == 'name':
                continue
            else:
                json_update['本科'][value1['name']] = {}
                for key2, value2 in value1.items():
                    if type(value2) == str:
                        continue
                    else:
                        print(type(value2))
                        for key3, value3 in value2.items():
                            if type(value3) == str:
                                continue
                            else:
                                print(value3)
                                json_update['本科'][value1['name']][key3] = value3['zymc']
    if value['name'] == '高职（专科）':
        json_update['专科'] = {}
        for key1, value1 in value.items():
            if key1 == 'name':
                continue
            else:
                json_update['专科'][value1['name']] = {}
                for key2, value2 in value1.items():
                    if type(value2) == str:
                        continue
                    else:
                        print(type(value2))
                        for key3, value3 in value2.items():
                            if type(value3) == str:
                                continue
                            else:
                                print(value3)
                                json_update['专科'][value1['name']][key3] = value3['zymc']

# 打开一个文件并写入 JSON 数据
with open('json/majorMap.json', 'w', encoding='utf-8') as f:
    json.dump(json_update, f, ensure_ascii=False, indent=4)
